home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
-
- Hub's Drop Shell 1.0
- ©Copyright 1995, Hubert Figuière, All right reserved.
-
- January 29th, 1995
- Modified April 27th, 1995
-
- Author :
- Hubert Figuière HF
-
- Purpose : this a shell used for creating simple Drag'n Drop application
- Modified for Painted Black with generic and specific enhancements.
-
- Features :
- -relies on System 7
- -implements menus and about Box
- -support 4 required apple events
-
- 01/21/95
- -initial release (HF)
- 01/29/95
- -moved AppleEvents stuff to HDSAEstuff.c (HF)
- 03/11/95
- -compiled for CW 5.5 (HF)
- 03/18/95
- -Modified specially for Painted Black (HF)
- 03/21/95
- -added support for auto foreground switching (HF)
- 04/26/95
- -finished support for auto PaintBlack... (HF)
- 04/27/95
- -corrected bug with keymap (HF)
-
- ******************************************************************************/
-
-
- #include <AppleEvents.h>
- #include <GestaltEqu.h>
-
- #include "QuickQD.h" //for QuickQD Macros...
-
- #include "HDSdefinitions.h"
- #include "HDSAEstuff.h"
- #include "HDSCustom.h"
-
- #ifdef __powerc
- QDGlobals qd;
- #endif
-
- Boolean finished = False; //nothing else to do
- MenuHandle menus [MENUNUM]; //menus in menubar
- short gDrag_n_drop; //drag n drop launch
- RgnHandle gMouse_moved_rgn; //region for mouse-moved events
- long gFadeDelay = 3600 * 5; //5 minutes before fade
-
-
- //for functions prototypes, see HDSdefinitions.h
-
-
- void init()
- /*Initialize the application*/
- {
- LongInt info; /*gestalt response*/
- Str255 msg; /*message displayed*/
- Integer i; //counter
- RgnHandle temp_rgn; /*temporary Rgn*/
- Rect temp_rect; /*temporary rect*/
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- MaxApplZone();
-
- FlushEvents(everyEvent,0); /*flush all the OSEvents pending. High-Level Events are not affected*/
-
- if (Gestalt(gestaltAppleEventsAttr,&info) || !BitTst(&info, 31-gestaltAppleEventsPresent))
- { /* if no AppleEvent manager */
- GetIndString(msg, kStringsID, kGestaltErrNum);
- ParamText(msg, "\p", "\p", "\p");
- /*item*/StopAlert(kErrorALRTID, NULL);
- ExitToShell(); /* Exit app */
- }
- if (init_AE())
- {
- for (i=0;i<3;i++)
- SysBeep(10);
- ExitToShell(); //quit after problems
- }
- for (i=0;i<MENUNUM;i++)
- {
- menus[i]=GetMenu(MAPPLEID+i); //get the menu
- InsertMenu(menus[i],0); //insert the menu
- }
- AddResMenu(menus[0],'DRVR'); //add the DAs into the menu
- DrawMenuBar(); /*draw the menu bar */
-
- GetCurrentProcess(&gMy_pid); //retrieve our process number
-
- //mouse-moved rgn
- gMouse_moved_rgn=NewRgn();
- temp_rgn=NewRgn();
- SetRect(&temp_rect,qd.screenBits.bounds.left,qd.screenBits.bounds.bottom-1,qd.screenBits.bounds.left+1,qd.screenBits.bounds.bottom);
- // InsetRect(&temp_rect,-2,-2);
- RectRgn(temp_rgn,&temp_rect);
-
- RectRgn(gMouse_moved_rgn,&qd.screenBits.bounds);
- /*
- Here is how gMouse_moved_rgn looks like :
- +--------------------------+
- | |
- | |
- | |
- | Screen |
- | |
- | |
- | |
- + |
- hot->\ |
- spot +------------------------+
- The point in the corner is the hot spot...
- */
- DiffRgn(gMouse_moved_rgn,temp_rgn,gMouse_moved_rgn);
- }
-
-
-
- void display_error (short err_type, OSErr the_err)
- {
- Str255 msg, err_str;
-
- GetIndString(msg, kStringsID, err_type);
- NumToString(the_err, err_str);
- ParamText(msg, err_str, "\p", "\p");
- /*item=*/
- StopAlert(kErrorALRTID, NULL);
- }
-
-
- void do_about()
- {
- Integer item; /*item selected*/
- DialogPtr about_dlog; /*dialog that is going to be displayed*/
-
- about_dlog = GetNewDialog(kAboutDLOGID, NULL, (DialogPtr)-1);
- ModalDialog(NULL, &item);
- DisposeDialog(about_dlog);
- }
-
-
- void handle_os_event(EventRecord* evt)
- {
- //0xFA000000
- if (evt->message & 0xFA000000) /* mouse moved event */
- PaintedBlack();
- }
-
-
-
- void handle_key(EventRecord* evt)
- {
- if (evt->modifiers & cmdKey)
- handle_menus(MenuKey(LoWord(evt->message) & charCodeMask));
- }
-
-
- void handle_menus(long selection) //handle menus
- {
- long final_ticks; /* number of ticks after Delay()*/
- switch (HiWord(selection))
- {
- case MAPPLEID:
- do_about();
- break;
- case MFILEID:
- switch (LoWord(selection))
- {
- case MFileOpen:
- Delay(FADE_NOW_DELAY,&final_ticks); /* wait 1/4 of second */
- do_it();
- break;
- case MFileQuit:
- finished=True;
- }/*switch*/
- }/*switch*/
- HiliteMenu(0);
- }
-
-
- void handle_mousedown(EventRecord* evt)
- {
- WindowPtr pointed_win;
-
- switch (FindWindow(evt->where,&pointed_win))
- {
- case inMenuBar:
- handle_menus(MenuSelect(evt->where));
- break;
- }
- }
-
-
- void main()
- {
- EventRecord evt; /*event record of the received event*/
- Point mouse_pt; /*mouse loc*/
- Point previous_mouse_pt;
- unsigned long last_time; //last time an event occured;
- unsigned long current_time; //current time
- KeyMap the_keys; //pressed keys
-
- init(); /*initialize the app*/
-
- GetMouse(&previous_mouse_pt);
- LocalToGlobal(&previous_mouse_pt);
- last_time = TickCount();
-
- while (!finished)
- {
- if(WaitNextEvent(EVTMASK, &evt, IDLETIME, gMouse_moved_rgn)) //wait for events
- {
- switch (evt.what)
- {
- case kHighLevelEvent: /*there are AppleEvents*/
- /*err =*/ AEProcessAppleEvent(&evt); /*process the apple event*/
- break;
- case mouseDown:
- handle_mousedown(&evt);
- break;
- case keyDown:
- handle_key(&evt);
- break;
- case osEvt:
- handle_os_event(&evt);
- }/*switch*/
- //*(long *)&previous_mouse_pt = *(long *)&mouse_pt; //SetPt() (faster)
- QuickCopyPt(previous_mouse_pt, mouse_pt);
- last_time = evt.when; //an event occurred, so tell him
- }
- else
- {
- GetMouse(&mouse_pt);
- LocalToGlobal(&mouse_pt);
- current_time = TickCount();
- // ATTENTION Partie Crade de C.... Faite pour comparer très vite et efficace...
- //if (!(*(long *)&previous_mouse_pt == *(long *)&mouse_pt)) //faster than EqualPt
- if (!QuickEqualPt(previous_mouse_pt, mouse_pt))
- { // if mouse moved since last time...
- //*(long *)&previous_mouse_pt = *(long *)&mouse_pt; //SetPt() (faster)
- QuickCopyPt(previous_mouse_pt, mouse_pt);
- last_time = current_time;
- if (switch_not_required && !PtInRgn(mouse_pt,gMouse_moved_rgn))
- /* only enter in this part if a switch is not yet required */
- obscure();
- }
- else
- {
- GetKeys(the_keys);
- /*
-
- */
- if ( the_keys[0] || the_keys[1] || the_keys[2]
- || the_keys[3] || Button()) //check for key down or button
- {
- //(*(long *)&previous_mouse_pt = *(long *)&mouse_pt); //SetPt() (faster)
- QuickCopyPt(previous_mouse_pt, mouse_pt);
- last_time = current_time; //event occured
- }
- else if (current_time - last_time >= gFadeDelay)
- {
- obscure();
- PaintedBlack();
- last_time = current_time;
- }
- }
- }
-
- if (gDrag_n_drop>=0)
- gDrag_n_drop--;
- }
- }
-